using System;

namespace DataBroker.Criteria
{
    /// <summary>
    /// This class defines operators used to combine logical expressions
    /// for WHERE clauses. It defines operators And and Or.
    /// </summary>
    [Serializable]
    public class Logical 
    {

        // --------------------------------------------------------- INSTANCE VARIABLES
        /// <summary>
        /// Boolean And connector 
        /// </summary>
        static public  readonly  Logical And              = new Logical(1);
        /// <summary>
        /// Boolean Or connector
        /// </summary>
        static public  readonly  Logical Or               = new Logical(2);

        /// <summary>
        /// Internal flag describing how this binding relates to the
        /// previous binding in a search criteria.
        /// </summary>
        private int searchBoolean;

        // --------------------------------------------------------- CLASS CONSTRUCTORS    
    
        /// <summary>
        /// Default constructor.
        /// </summary>
        public Logical() 
        {
			
        }

        /// <summary>
        /// Private constructor for static variables.
        /// </summary>
        /// <param name="sb"></param>
        private Logical(int sb) 
        {
            searchBoolean = sb;
        }
        ///<summary>
        /// Returns the boolean value from a string
        ///</summary>
        ///<param name="op">Operator as a string</param>
        ///<returns></returns>
        public static Logical BooleanFromString(string op)
        {
            if (op == "Or")
                return Or;
            return And;
        }


        /// <summary>
        /// Returns the current boolean operator.
        /// </summary>
        /// <returns>Current boolean operator.</returns>
        public override String ToString() 
        {
            switch( searchBoolean ) 
            {
                case 1:
                    {
                        return "And";
                    }
                case 2:
                    {
                        return "Or";
                    }
                default:
                    {
                        return "UNKNOWN";
                    }
            }
        } // END OF toString
    
    }
}